import { Node, Vec3 } from 'cc';
import { ecs } from 'db://app-game/libs/ecs/ECS';
import { AStar } from 'db://app-game/libs/math/AStar/AStar';
import { Graph } from 'db://app-game/libs/math/graph/Graph';
import FlowGrid from 'db://app-game/libs/math/pathfinding/flow-field/FlowGrid';
import { StaticCreature } from '../../static-creature/StaticCreature';
import { MapBaseInfo, ObstacleBaseInfo, UnloadMapInfo } from '../LevelMap.type';

/** 地图渲染模型组件 */
@ecs.register('LevelMapModelRender')
export class LevelMapModelRenderComp extends ecs.Comp {
  /** 地图渲染完成 */
  onRenderFinish: boolean = false;
  /** 时间 */
  time: number = 0;
  /** 地图卸载缓存时间 */
  unloadCacheTime: number = 5;
  /** 中心节点 */
  target: Node | Vec3 | null = null;
  /** 当前地图索引 */
  currentMapIndex: { row: number; col: number } = { row: -1, col: -1 };
  /** 当前渲染的地图 */
  currentMap: Map<string, MapBaseInfo> = new Map();
  /** 卸载地图池 */
  unloadMapPool: Map<string, UnloadMapInfo> = new Map();
  /** 障碍物信息 */
  obstacleMap: Map<string, Map<string, ObstacleBaseInfo>> = new Map();
  /** 静态生物信息 */
  staticCreatureMap: Map<string, StaticCreature[]> = new Map();
  /** 流动网格 */
  flowGrid: FlowGrid = null;
  /** A星网络 */
  AStar: AStar | null = null;
  /** 图 */
  graph: Graph | null = null;
  reset(entity: ecs.Entity): void {
    this.time = 0;
    this.unloadCacheTime = 5;
    this.target = null;
    this.currentMapIndex = { row: -1, col: -1 };
    this.currentMap = new Map();
    this.unloadMapPool = new Map();
    this.obstacleMap = new Map();
    this.staticCreatureMap = new Map();
    this.flowGrid = null;
    this.AStar = null;
    this.graph = null;
  }
}
